home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H145.ZIP / ASXXXX_3.ZIP / M09ADR.C < prev    next >
C/C++ Source or Header  |  1990-07-18  |  4KB  |  284 lines

  1. /* M09ADR:C */
  2.  
  3. /*
  4.  * (C) Copyright 1989,1990
  5.  * All Rights Reserved
  6.  *
  7.  * Alan R. Baldwin
  8.  * 721 Berkeley St.
  9.  * Kent, Ohio  44240
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <setjmp.h>
  14. #include "asm.h"
  15. #include "m6809.h"
  16.  
  17. int index;
  18.  
  19. int
  20. addr(esp)
  21. register struct expr *esp;
  22. {
  23.     register c;
  24.  
  25.     index = 0;
  26.     if ((c = getnb()) == '#') {
  27.         expr(esp, 0);
  28.         esp->e_mode = S_IMMED;
  29.     } else
  30.     if (c == '[') {
  31.         index = 0x90;
  32.         addr1(esp);
  33.         if (getnb() != ']') {
  34.             aerr();
  35.         }
  36.     } else {
  37.         unget(c);
  38.         addr1(esp);
  39.     }
  40.     return (esp->e_mode);
  41. }
  42.  
  43. int
  44. addr1(esp)
  45. register struct expr *esp;
  46. {
  47.     register c;
  48.  
  49.     if (admode(abd)) {
  50.         comma();
  51.         if (!admode(xyus))
  52.             aerr();
  53.         esp->e_mode = S_IND;
  54.         esp->e_flag = 0;
  55.         esp->e_addr = 0;
  56.         esp->e_base.e_ap = NULL;
  57.     } else
  58.     if ((c = getnb()) == ',') {
  59.         if (admode(xyus)) {
  60.             index |= 0x04;
  61.         } else
  62.         if (admode(auto2)) {
  63.             ;
  64.         } else
  65.         if (!(index & 0x10) && admode(auto1)) {
  66.             ;
  67.         } else {
  68.             aerr();
  69.         }
  70.         esp->e_mode = S_IND;
  71.         esp->e_flag = 0;
  72.         esp->e_addr = 0;
  73.         esp->e_base.e_ap = NULL;
  74.     } else
  75.     if (c == '*') {
  76.         expr(esp, 0);
  77.         esp->e_mode = S_DIR;
  78.         if ((c = getnb()) == ',') {
  79.             if (admode(xyus)) {
  80.                 esp->e_mode = S_OFST;
  81.             } else
  82.             if (admode(pcr)) {
  83.                 esp->e_mode = S_PCR;
  84.             } else
  85.             if (admode(pc)) {
  86.                 esp->e_mode = S_PC;
  87.             } else {
  88.                 aerr();
  89.             }
  90.         } else {
  91.             unget(c);
  92.         }
  93.     } else {
  94.         unget(c);
  95.         expr(esp, 0);
  96.         if ((c = getnb()) == ',') {
  97.             if (admode(xyus)) {
  98.                 esp->e_mode = S_OFST;
  99.             } else
  100.             if (admode(pcr)) {
  101.                 esp->e_mode = S_PCR;
  102.             } else
  103.             if (admode(pc)) {
  104.                 esp->e_mode = S_PC;
  105.             } else {
  106.                 aerr();
  107.             }
  108.         } else {
  109.             unget(c);
  110.             esp->e_mode = S_EXT;
  111.         }
  112.     }
  113.     return (esp->e_mode);
  114. }
  115.  
  116.     
  117. /*
  118.  * Enter admode() to search a specific addressing mode table
  119.  * for a match. Return the addressing value on a match or
  120.  * zero for no match.
  121.  */
  122. int
  123. admode(sp)
  124. register struct adsym *sp;
  125. {
  126.     register char *ptr;
  127.     register int i, v;
  128.     unget(getnb());
  129.     i = 0;
  130.     while ( *(ptr = (char *) &sp[i]) ) {
  131.         if (srch(ptr)) {
  132.             v = sp[i].a_val;
  133.             index |= (v | 0x80);
  134.             return(v);
  135.         }
  136.         i++;
  137.     }
  138.     return(0);
  139. }
  140.  
  141. /*
  142.  *      srch --- does string match ?
  143.  */
  144. int
  145. srch(str)
  146. register char *str;
  147. {
  148.     register char *ptr;
  149.     ptr = ip;
  150.  
  151. #if    CASE_SENSITIVE
  152.     while (*ptr && *str) {
  153.         if (*ptr != *str)
  154.             break;
  155.         ptr++;
  156.         str++;
  157.     }
  158.     if (*ptr == *str) {
  159.         ip = ptr;
  160.         return(1);
  161.     }
  162. #else
  163.     while (*ptr && *str) {
  164.         if (ccase[*ptr] != ccase[*str])
  165.             break;
  166.         ptr++;
  167.         str++;
  168.     }
  169.     if (ccase[*ptr] == ccase[*str]) {
  170.         ip = ptr;
  171.         return(1);
  172.     }
  173. #endif
  174.  
  175.     if (!*str)
  176.         if (any(*ptr," \t\n,];")) {
  177.             ip = ptr;
  178.             return(1);
  179.         }
  180.     return(0);
  181. }
  182.  
  183. /*
  184.  *      any --- does str contain c?
  185.  */
  186. int
  187. any(c,str)
  188. char    c, *str;
  189. {
  190.     while (*str)
  191.         if(*str++ == c)
  192.             return(1);
  193.     return(0);
  194. }
  195.  
  196. struct adsym    abd[] = {    /* a, b, or d indexed offset */
  197.     "a",    0x06,
  198.     "b",    0x05,
  199.     "d",    0x0B,
  200.     "",    0x00
  201. };
  202.  
  203. struct adsym    xyus[] = {    /* x, y, u, or s index register */
  204.     "x",    0x100,
  205.     "y",    0x120,
  206.     "u",    0x140,
  207.     "s",    0x160,
  208.     "",    0x000
  209. };
  210.  
  211. struct adsym    auto1[] = {    /* auto increment/decrement by 1 */
  212.     "x+",    0x100,
  213.     "-x",    0x102,
  214.     "y+",    0x120,
  215.     "-y",    0x122,
  216.     "u+",    0x140,
  217.     "-u",    0x142,
  218.     "s+",    0x160,
  219.     "-s",    0x162,
  220.     "",    0x000
  221. };
  222.  
  223. struct adsym    auto2[] = {    /* auto increment/decrement by 2 */
  224.     "x++",    0x101,
  225.     "--x",    0x103,
  226.     "y++",    0x121,
  227.     "--y",    0x123,
  228.     "u++",    0x141,
  229.     "--u",    0x143,
  230.     "s++",    0x161,
  231.     "--s",    0x163,
  232.     "",    0x000
  233. };
  234.  
  235. struct adsym    pc[] = {    /* pc */
  236.     "pc",    0x0C,
  237.     "",    0x00
  238. };
  239.  
  240. struct adsym    pcr[] = {    /* pc relative */
  241.     "pcr",    0x0C,
  242.     "",    0x00
  243. };
  244.  
  245. struct adsym    regs[] = {    /* exg, tfr register coding */
  246.     "d",    0x100,
  247.     "x",    0x101,
  248.     "y",    0x102,
  249.     "u",    0x103,
  250.     "s",    0x104,
  251.     "pc",    0x105,
  252.     "a",    0x108,
  253.     "b",    0x109,
  254.     "cc",    0x10A,
  255.     "dp",    0x10B,
  256.     "",    0x000
  257. };
  258.  
  259. struct adsym    stks[] = {    /* push/pull on system stack */
  260.     "cc",    0x01,
  261.     "a",    0x02,
  262.     "b",    0x04,
  263.     "d",    0x06,
  264.     "dp",    0x08,
  265.     "x",    0x10,
  266.     "y",    0x20,
  267.     "u",    0x40,
  268.     "pc",    0x80,
  269.     "",    0x00
  270. };
  271.  
  272. struct adsym    stku[] = {    /* push/pull on user stack */
  273.     "cc",    0x01,
  274.     "a",    0x02,
  275.     "b",    0x04,
  276.     "d",    0x06,
  277.     "dp",    0x08,
  278.     "x",    0x10,
  279.     "y",    0x20,
  280.     "s",    0x40,
  281.     "pc",    0x80,
  282.     "",    0x00
  283. };
  284.